<?php
Class CashAction extends Action{
	public function user(){
		$user['id'] =$this->userid = intval(I('id'));
		$this->user = $user = M('User')->where($user)->find();//当前用户的一些基本信息

		//$openid=$user['openid'];
        $condition['a.openid']=$user['openid'];
        $condition['a.status']=2;//支付成功

		import('ORG.Util.EditPage');
		$count = M()->Table('box_user_order a')->join('box_user_order_detail b on a.order_num=b.order_num')->field("a.paytime,b.*")->where($condition)->count();
		$Page = new Page($count,10);
        $Page->setConfig('theme',"<ul class='pagination'><li><a>%totalRow% %header% %nowPage%/%totalPage% 页</a></li><li>%upPage%</li><li>%first%</li><li>%prePage%</li><li>%linkPage%</li><li>%nextPage%</li><li>%end%</li><li>%downPage%</li>".$gopagenu."</ul>");
		$this->page = $Page->show();
        //$this->discuss =  M('UserPoints')->where($condition)->order("id desc")->limit($Page->firstRow.','.$Page->listRows)->select();
        $list = M()->Table('box_user_order a')->join('box_user_order_detail b on a.order_num=b.order_num')->field("a.paytime,b.*")->where($condition)->limit($Page->firstRow.','.$Page->listRows)->select();
        foreach ($list as $key => $value) {
            switch ($value['paytype']) {
                case '1':
                    $name = M()->Table('box_medical_records a')->join('box_user b on a.user_id = b.id')->where("a.id = {$value['item_id']}")->field('b.name')->getField('name');
                    $package[]=array("action"=>'单份病例','content'=>"专家：{$name} 病例编号：{$value['id']} 使用金豆:{$value['points']}","fee"=>"-{$value['fee']}","time"=>date('Y.m.d',$value['paytime']));
                    if($value['status']==3){
                        $package[]=array("action"=>'病例退款','content'=>"专家：{$name} 病例编号：{$value['id']} 使用金豆:{$value['points']}","fee"=>"+{$value['fee']}");
                    }
                    break;
                case "2":
                    $name = M('User')->where("id={$value['item_id']}")->getField('name');
                    $package[]=array("action"=>'订阅病例','content'=>"专家：{$name} 订阅周期：{$value['nums']}月 使用金豆:{$value['points']}","fee"=>"-{$value['fee']}","time"=>date('Y.m.d',$value['paytime']));
                    if($value['status']==3){
                        $package[]=array("action"=>'订阅退款','content'=>"专家：{$name}  订阅周期：{$value['nums']}月 使用金豆:{$value['points']}","fee"=>"+{$value['fee']}","time"=>date('Y.m.d',$value['returntime']));
                    }
                    break;
                case "3":
                    $name = M('User')->where("id={$value['item_id']}")->getField('name');
                    $package[]=array("action"=>'历史病例','content'=>"专家：{$name} 使用金豆:{$value['points']}","fee"=>"-{$value['fee']}","time"=>date('Y.m.d',$value['paytime']));
                    if($value['status']==3){
                        $package[]=array("action"=>'历史退款','content'=>"专家：{$name} 使用金豆:{$value['points']}","fee"=>"+{$value['fee']}","time"=>date('Y.m.d',$value['returntime']));
                    }
                    break; 
                case "4":
                    $name = M('User')->where("id={$value['item_id']}")->getField('name');
                    $package[]=array("action"=>'邀请专家','content'=>"专家：{$name} 使用金豆:{$value['points']}","fee"=>"-{$value['fee']}","time"=>date('Y.m.d',$value['paytime']));
                    if($value['status']==3){
                        $package[]=array("action"=>'邀请退款','content'=>"专家：{$name} 使用金豆:{$value['points']}","fee"=>"+{$value['fee']}","time"=>date('Y.m.d',$value['returntime']));
                    }
                    break;
                case "5":
                    $name = M('Event')->where("id={$value['item_id']}")->getField('name');
                    $package[]=array("action"=>'参加活动','content'=>"活动：{$name} 使用金豆:{$value['points']}","fee"=>"-{$value['fee']}","time"=>date('Y.m.d',$value['paytime']));
                    if($value['status']==3){
                        $package[]=array("action"=>'活动退款','content'=>"活动：{$name} 使用金豆:{$value['points']}","fee"=>"+{$value['fee']}","time"=>date('Y.m.d',$value['returntime']));
                    }
                    break;
                case "6":
                    $points = $value['fee']*100;
                    $package[]=array("action"=>'购买金豆','content'=>"{$points}","fee"=>"-{$value['fee']}","time"=>date('Y.m.d',$value['paytime']));
                    break;
            }
        }

        $this->cash = $package;

        $this->currentpage = $Page->firstRow + 1; 	
        $this->display();
	}
}